package cn.lg.soar.mvc.config;

import cn.lg.soar.mvc.filter.IpWhitelistFilter;
import jakarta.servlet.FilterRegistration;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Configuration;

import java.util.Set;

@Configuration
public class CustomWebAppInitializer extends SpringBootServletInitializer implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        IpWhitelistFilter filter = new IpWhitelistFilter(Set.of("192.168.205.55"));
        // 注册过滤器
        FilterRegistration.Dynamic dynamic = servletContext.addFilter("myFilter", filter);
        dynamic.addMappingForUrlPatterns(null, false, "/*"); // 设置过滤所有请求
        // 可以设置初始化参数等其他属性
    }

}
